/**
 * All Rights Reserved , Copyright (C) 2021 , 青岛鼎信通讯股份有限公司
 *
 *SdVueComponentsController
 * SD组件档案(vue)
 *
 * 修改纪录
 * 2021-11-19 版本：1.0 jiangtao 创建。
 * @version 版本：1.0
 * @author 作者：jiangtao
 * 创建日期：2021-11-19
 */

package com.topscomm.gpm.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.topscomm.cbo.model.TreeModel;
import com.topscomm.gpm.controller.auto.GpmVueComponentsControllerAuto;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.topscomm.pub.util.StringBufferProxy;
import com.topscomm.pub.util.StringUtil;
import com.topscomm.pub.vo.ResponseResult;

/**
 * @author: jiangtao
 * @date: 2021-11-19
 * @description:SD组件档案(vue)Controller
 * @modify:
 */
@RestController
@RequestMapping("sd/vueComponents")
public class GpmVueComponentsController extends GpmVueComponentsControllerAuto implements IGpmVueComponentsController {
	/**
	 * @author: jiangtao
	 * @date: 2021-11-19
	 * @param paraMap
	 * @return
	 * @description:转换出查询SQL语句
	 * @modify:
	 */
	@Override
	protected String spellListSql(Map<String, Object> paraMap) {
		StringBufferProxy sql = new StringBufferProxy();
		sql.appendSingle(" 1=1 ");
		if (paraMap.containsKey("qry_name")) {
			String value = paraMap.get("qry_name").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and name like '%{0}%' ", value);
		}
		if (paraMap.containsKey("qry_code")) {
			String value = paraMap.get("qry_code").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and code = '{0}' ", value);
		}
		if (paraMap.containsKey("qry_tabid")) {
			String value = paraMap.get("qry_tabid").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and tabid = '{0}' ", value);
		}
		return sql.toString();
	}

	/**
	 * @author: jiangtao
	 * @date: 2021-11-19
	 * @param paraMap
	 * @return
	 * @description:转换出查询SQL语句
	 * @modify:
	 */
	@Override
	@GetMapping(value = "/refList")
	public ResponseResult<Object> refList(@RequestParam(required = false) Map<String, Object> paraMap) {
		return super.refList(paraMap);
	}

	/***
	 * @description: 树查询方法
	 * @param paraMap
	 * @return
	 * @author: jiangtao1
	 * @date: 2021/11/19 16:58
	 * @modify:
	 */
	@GetMapping(value = "/queryTreeList")
	public ResponseResult<Object> queryTreeList(@RequestParam(required = false) Map<String, Object> paraMap) {
		String sqlWhere = this.spellListSql(paraMap);
		sqlWhere += " order by code asc";
		List<Map<String, Object>> listModule = this.service.queryMapByWhere(sqlWhere);
		List<Map<String, Object>> listNewModule = new ArrayList<Map<String, Object>>();
		listNewModule.addAll(listModule);
		TreeModel treeModel = new TreeModel();
		List<TreeModel> treeList = treeModel.buildTree(listNewModule, true, "组件档案(vue)树");
		Map<String, Object> dataMap = new HashMap<>();
		dataMap.put("dataList", treeList);
		return ResponseResult.ok(dataMap);
	}
}

